<?php

namespace adminApi\modules\guest\controllers;

use adminApi\models\db\Adminers;
use Carbon\Carbon;
use common\components\fast_api\Controller;
use common\components\wtools\tools\Security;
use common\datas\Enums;
use common\Tools;

class SiteController extends Controller
{
    /**
     * 登录
     * @desc JWT登录
     * @param string $mobile 手机号
     * @param string $password 密码
     * @return mixed
     */
    public function actionLogin($mobile, #[SensitiveParamter] $password)
    {
//        $password = md5($password);
//        $password = md5($password);
        $adminer = Adminers::findOne(['mobile' => $mobile]);
        if (!$adminer || !$adminer->validatePassword($password)){
            return $this->apiError("账号或密码错误");
        }
        if ($adminer->status !== Enums::ACTIVE) {
            return $this->apiError("用户已被封禁");
        }
        $jwtData = $adminer->generateJwtTokenData();
        $authInfo = \Yii::$app->adminApiTool->setJwtTokenData($jwtData)->post('/rbac/adminer/auth-info');
        return $this->apiSuccess([
            'jwtData' => $jwtData,
            'authInfo' => $authInfo,
        ]);
    }
}
